<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */

namespace MoChat\App\Client\Logic\FollowRecord;

use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use MoChat\App\Client\Contract\ClientFollowRecordContract;


/**
 * 跟进记录新增.
 *
 */
class CreateLogic
{
    /**
     * @Inject
     * @var ClientFollowRecordContract
     */
    protected $clientFollowRecordService;


    /**
     * 成员列表.
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function handle(array $params): array
    {
        //返回的数据格式
        $data = [];
        $params=[
            'type'=>$params['type'],
            'client_id'=>$params['clientId'],
            'user_id'=>Db::table('work_employee')->where('log_user_id',$params['user']['id'])->value('id'),
            'remark'=>$params['remark'],
            'created_at'=>date('Y-m-d H:i:s'),
            'followed_at'=>$params['followedAt'],
            'returned_at'=>$params['returnedAt']?$params['returnedAt']:null,
            'work_contact_id'=>$params['work_contact_id']??0
        ];
        $this->clientFollowRecordService->createClientFollowRecord($params);
        return $data;
    }


}
